package metro.jme.lottery.graphics;

import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.TiledLayer;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author pierre
 */
public class Background extends TiledLayer {

  private static final String IMAGE_FILENAME = "/background.png";
  private static final int IMAGE_COLUMNS = 8;
  private static final int IMAGE_ROWS = 2;
  private static final int MAP_COLUMNS = 8;
  private static final int MAP_ROWS = 8;
  private static final int m_map[][] = {
    {0, 0, 8, 0, 0, 0, 0, 0},
    {0, 0, 2, 0, 0, 0, 0, 0},
    {7, 0, 10, 8, 0, 0, 7, 0},
    {3, 0, 1, 4, 0, 0, 4, 0},
    {11, 0, 9, 12, 0, 0, 12, 0},
    {1, 0, 4, 3, 0, 0, 2, 0},
    {9, 0, 12, 11, 0, 0, 10, 0},
    {5, 15, 14, 13, 16, 15, 6, 16}
  };
  private static Image m_image;

  private static final Image getImage() {
    try {
      m_image = Image.createImage(IMAGE_FILENAME);
    } catch (Exception e) {
      System.err.println("Error loading background image");
      return null;
    }
    return m_image;
  }

  public Background() {
    super(MAP_COLUMNS,
	    MAP_ROWS,
	    getImage(),
	    m_image.getWidth() / IMAGE_COLUMNS,
	    m_image.getHeight() / IMAGE_ROWS);

    for (int row = MAP_ROWS - 1; row >= 0; row--) {
      for (int column = MAP_COLUMNS - 1; column >= 0; column--) {
	setCell(column, row, m_map[row][column]);
      }
    }

  }
}
